import 'dart:math';

import 'package:aqua_plunge/util/MedalType.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:get/get_core/src/get_main.dart';

import '../widget/hi_webview.dart';

SizedBox hiSpace({double height = 1, double width = 1}) {
  return SizedBox(height: height, width: width);
}

double getDeviceTop(BuildContext context) {
  return MediaQuery.of(context).padding.top;
}

///添加阴影
Widget shadowWarp({required Widget child, EdgeInsetsGeometry? padding}) {
  return Container(
    padding: padding,
    decoration: const BoxDecoration(
        gradient: LinearGradient(
            colors: [Color(0x66000000), Colors.transparent],
            begin: Alignment.topCenter,
            end: Alignment.bottomCenter)),
    child: child,
  );
}

void shuffleList(List list) {
  final random = Random();
  for (int i = list.length - 1; i > 0; i--) {
    // 获取一个从0到i的随机索引
    final index = random.nextInt(i + 1);
    // 交换当前元素和随机索引的元素
    var temp = list[i];
    list[i] = list[index];
    list[index] = temp;
  }
}

jumpH5({String? url, String? title, bool? hideAppBar, String? statusBarColor}) {
  if (url == null) return;
  Get.to(HiWebview(
    url: url,
    title: title,
    hideAppBar: hideAppBar
  ));
}

getPathByMedalType(MedalType type){

  switch(type){
    case MedalType.level1:
      return 'images/icon_level1.png';
    case MedalType.level2:
      return 'images/icon_level2.png';
    case MedalType.level3:
      return 'images/icon_level3.png';
    case MedalType.level4:
      return 'images/icon_level4.png';
    case MedalType.upgrade1:
      return 'images/icon_super_level1.png';
    case MedalType.upgrade2:
      return 'images/icon_super_level2.png';
    case MedalType.upgrade3:
      return 'images/icon_super_level3.png';
    case MedalType.upgrade4:
      return 'images/icon_super_level4.png';
  }
}

requestPermissionDialog(BuildContext context,String title,Function confirm){
  showDialog(context: context, builder: (_){
    return AlertDialog(
      title: Text(title),
      actions: [
        TextButton(onPressed: (){
          Get.back();
        }, child: const Text('Return')),
        TextButton(onPressed: (){
           Get.back();
           confirm();
        }, child:const Text('Yes'))
      ],
    );
  });
}

